<template>
    <div class="etsy-load">
        <Login ref="login" @close="close"></Login>
    </div>
</template>
<script>
import { mapGetters } from "vuex";
export default {
    name: "etsyLoadUrl",
    layout: "layout-empty",
    data () {
        return {
            allow: false,
        };
    },
    computed: {
        ...mapGetters({
            isLogin: "getIsLogin",
        }),
        query: {
            get () {
                return this.$route.query || {};
            },
        },
    },
    methods: {
        async connectEtsy () {
            let reqData = this.$route.query;
            if (Object.keys(reqData).length == 0) {
                return;
            }
            this.allow = true;
            let response = await this.$http("AppStore.bindEtsyShop", reqData);

            if (response.code == 0) {
                //成功回调
                this.$gmeRepore('addToStore');
                this.$router.replace("/user/store");
            } else {
                this.$uxMessage({
                    type: "warning",
                    showClose: true,
                    duration: 99999,
                    message: response.msg,
                });
            }
        },
        close () {
            if (this.allow) {
                return;
            }
            // this.$router.replace("/");
        },
    },
    mounted () {
        if (!this.isLogin) {
            this.$emit("global:userLogin", () => {
                this.connectEtsy();
            });
        } else {
            this.connectEtsy();
        }
    },
};
</script>
<style>
.login-close {
    display: none;
}
</style>
